<?
	include('chksession.php');
	session_start();
    $data = file_get_contents("php://input");
    $objData = json_decode($data);
	
	   $msg='';
	   $custtype= $objData->custtype;
       $prefx= $objData->prefx;
	   $name= $objData->Name;
	   $address= $objData->Address;
	   $city= $objData->city;
	   
	   $email= $objData->email;
	   $phoneno= $objData->phoneno;
	   $appadmchrg = $objData->appadmchrg;
	   $custid = $objData->custid;
	  
	   
	  echo $prefx.",".$name.",".$address.",".$city.",".$custtype.",".$email.",".$phoneno.",".$custid.",".$appadmchrg;

	   //exit;
	   
		$enteredby=$_SESSION['username'];
		
		include('conn.php');
		$sqlc="select count(*) cnt from customermast where status = 0 and custdesc='".$name."'";
		$resc=mysql_query($sqlc);
		$rowc=mysql_fetch_assoc($resc);
		if (strlen($name)>1)
		{
			if($rowc['cnt']==0)
			{
				$sql="insert into customermast(custtype,prefx,custdesc,address,city,email,phoneno, appadmchrg,enteredby,entrydt)
				values('".$custtype."','".$prefx."','".$name."','".$address."','".$city."','".$email."','".$phoneno."','".$appadmchrg."','".$enteredby."',sysdate())";
												
				$res=mysql_query($sql);
				if($res)
					$msg='Record saved successfully';			
			}
			else
			{
				$sql="update customermast set email='".$email."',entrydt=sysdate(),status=123 where custid=".$custid;
				$res=mysql_query($sql);
				if($res)
					$msg='Record updated successfully...';					
			}
		}
		else
		{
			$msg='Blank Name not Allowed';
		}			
	    echo $msg;
?>